package com.cbh.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.cbh.api.model.ApiResult;
import com.cbh.domain.service.OfferInterfaceService;
import com.cbh.entity.OfferInterface;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(description = "报价接口管理")
@RestController
@RequestMapping("/sign/v3/offer/interface")
public class OfferInterfaceController {
	@Autowired
	OfferInterfaceService oiService;

	/**
	 * 保存报价接口信息
	 * 
	 * @param product
	 * @return
	 */
	@ApiOperation(value = "报价接口信息保存", httpMethod = "POST")
	@RequestMapping(value = "", method = RequestMethod.POST, produces = "application/json")
	public ApiResult<String> save(
			@ApiParam(value = "报价接口信息", required = true) @RequestBody(required = true) OfferInterface ob) {
		ApiResult<String> apiResult = new ApiResult<>();
		try {
			String re = oiService.save(ob);
			return apiResult.success(re);
		} catch (Exception e) {
			return apiResult.fail(e.getMessage());
		}
	}

	/**
	 * 获取全部报价接口信息
	 * 
	 * @return
	 */
	@ApiOperation(value = "获取全部报价接口信息", httpMethod = "GET")
	@RequestMapping(value = "", method = RequestMethod.GET, produces = "application/json")
	public ApiResult<List<OfferInterface>> getAll() {
		ApiResult<List<OfferInterface>> apiResult = new ApiResult<>();
		try {
			List<OfferInterface> obs = oiService.getAll();
			return apiResult.success(obs);
		} catch (Exception e) {
			return apiResult.fail(e.getMessage());
		}
	}

	/**
	 * 获取报价接口信息
	 * 
	 * @param proId
	 * @return
	 */
	@ApiOperation(value = "获取报价接口信息", httpMethod = "GET")
	@ApiImplicitParams({ @ApiImplicitParam(paramType = "path", name = "id", dataType = "String", required = true) })
	@RequestMapping(value = "{id}", method = RequestMethod.GET, produces = "application/json")
	public ApiResult<OfferInterface> getOne(@PathVariable("id") String id) {
		ApiResult<OfferInterface> apiResult = new ApiResult<>();
		try {
			OfferInterface ob = oiService.getOne(id);
			return apiResult.success(ob);
		} catch (Exception e) {
			return apiResult.fail(e.getMessage());
		}
	}

	/**
	 * 禁用
	 * 
	 * @param id
	 * @return
	 */
	@ApiOperation(value = "获取报价接口信息", httpMethod = "DELETE")
	@ApiImplicitParams({ @ApiImplicitParam(paramType = "path", name = "id", dataType = "String", required = true) })
	@RequestMapping(value = "/id/{id}", method = RequestMethod.DELETE, produces = "application/json")
	public ApiResult<OfferInterface> disable(@PathVariable("id") String id) {
		ApiResult<OfferInterface> apiResult = new ApiResult<>();
		try {
			OfferInterface ob = oiService.getOne(id);
			return apiResult.success(ob);
		} catch (Exception e) {
			return apiResult.fail(e.getMessage());
		}
	}
}
